home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / lst / RCS / lstRemove.c,v < prev    next >
Encoding:
Text File  |  1992-05-19  |  3.1 KB  |  131 lines

  1. head     1.7;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.7
  10. date     89.06.13.15.01.51;  author adam;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.7
  21. log
  22. @checked in with -k by kupfer at 92.05.18.17.32.46.
  23. @
  24. text
  25. @/*-
  26.  * LstRemove.c --
  27.  *    Remove an element from a list
  28.  *
  29.  * Copyright (c) 1988 by University of California Regents
  30.  *
  31.  * Permission to use, copy, modify, and distribute this
  32.  * software and its documentation for any purpose and without
  33.  * fee is hereby granted, provided that the above copyright
  34.  * notice appears in all copies.  Neither the University of California nor
  35.  * Adam de Boor makes any representations about the suitability of this
  36.  * software for any purpose.  It is provided "as is" without
  37.  * express or implied warranty.
  38.  */
  39. #ifndef lint
  40. static char *rcsid =
  41. "$Id: lstRemove.c,v 1.7 89/06/13 15:01:51 adam Exp $ SPRITE (Berkeley)";
  42. #endif lint
  43.  
  44. #include    "lstInt.h"
  45.  
  46. /*-
  47.  *-----------------------------------------------------------------------
  48.  * Lst_Remove --
  49.  *    Remove the given node from the given list.
  50.  *
  51.  * Results:
  52.  *    SUCCESS or FAILURE.
  53.  *
  54.  * Side Effects:
  55.  *    The list's firstPtr will be set to NilListNode if ln is the last
  56.  *    node on the list. firsPtr and lastPtr will be altered if ln is
  57.  *    either the first or last node, respectively, on the list.
  58.  *
  59.  *-----------------------------------------------------------------------
  60.  */
  61. ReturnStatus
  62. Lst_Remove (l, ln)
  63.     Lst                  l;
  64.     LstNode          ln;
  65. {
  66.     register List     list = (List) l;
  67.     register ListNode    lNode = (ListNode) ln;
  68.  
  69.     if (!LstValid (l) ||
  70.     !LstNodeValid (ln, l)) {
  71.         return (FAILURE);
  72.     }
  73.     
  74.     /*
  75.      * unlink it from the list
  76.      */
  77.     if (lNode->nextPtr != NilListNode) {
  78.     lNode->nextPtr->prevPtr = lNode->prevPtr;
  79.     }
  80.     if (lNode->prevPtr != NilListNode) {
  81.     lNode->prevPtr->nextPtr = lNode->nextPtr;
  82.     }
  83.     
  84.     /*
  85.      * if either the firstPtr or lastPtr of the list point to this node,
  86.      * adjust them accordingly
  87.      */
  88.     if (list->firstPtr == lNode) {
  89.     list->firstPtr = lNode->nextPtr;
  90.     }
  91.     if (list->lastPtr == lNode) {
  92.     list->lastPtr = lNode->prevPtr;
  93.     }
  94.  
  95.     /*
  96.      * Sequential access stuff. If the node we're removing is the current
  97.      * node in the list, reset the current node to the previous one. If the
  98.      * previous one was non-existent (prevPtr == NilListNode), we set the
  99.      * end to be Unknown, since it is.
  100.      */
  101.     if (list->isOpen && (list->curPtr == lNode)) {
  102.     list->curPtr = list->prevPtr;
  103.     if (list->curPtr == NilListNode) {
  104.         list->atEnd = Unknown;
  105.     }
  106.     }
  107.  
  108.     /*
  109.      * the only way firstPtr can still point to ln is if ln is the last
  110.      * node on the list (the list is circular, so lNode->nextptr == lNode in
  111.      * this case). The list is, therefore, empty and is marked as such
  112.      */
  113.     if (list->firstPtr == lNode) {
  114.     list->firstPtr = NilListNode;
  115.     }
  116.     
  117.     /*
  118.      * note that the datum is unmolested. The caller must free it as
  119.      * necessary and as expected.
  120.      */
  121.     if (lNode->useCount == 0) {
  122.     free ((Address)ln);
  123.     } else {
  124.     lNode->flags |= LN_DELETED;
  125.     }
  126.     
  127.     return (SUCCESS);
  128. }
  129.  
  130. @
  131.